package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/2 10:51
 * @apiNote
 */

public class Test00485FindMaxConsecutiveOnes {
    public static void main(String[] args) {
        int[] a = new int[]{1, 1,1,0,1};
        int count = test(a);
        System.out.println(count + "  array:" + JSON.toJSON(a));
    }

    public static int test(int[] nums) {
        int curLen = 0;
        int max= 0;
        for(int i=0;i<nums.length;i++){
            if(nums[i] == 1){
                curLen++;
            }else{
                curLen = 0;
            }
            max = Math.max(max,curLen);
        }
        return max;
    }
}

